#  coding=utf-8

from .. import db

from .base import BaseModel


class Post(BaseModel):
    __tablename__ = 'post'
    id = db.Column(db.BIGINT, primary_key=True)
    title = db.Column(db.String(64), default='', doc='标题')
    content = db.Column(db.Text, default='', doc='介绍')
    author_id = db.Column(db.Integer, db.ForeignKey("user.id"), default=0, doc='作者')
    author = db.relationship('User', backref=db.backref('posts'))
    status = db.Column(db.SmallInteger, default=0, doc='状态')
    club_id = db.Column(db.BIGINT, db.ForeignKey("club.id"),  default='', doc='密码')
    club = db.relationship('Club', backref=db.backref('posts'))

    @staticmethod
    def insert_post():
        for i in range(25):
            article = Post(title=u'第一篇文章'+str(1),
                           content=u'第一篇文章'+str(1),
                           author_id=1,
                           club_id=1)
            db.session.add(article)
        db.session.commit()

    def __repr__(self):
        return f'<Post {self.title}r>'
